using System;
using System.Windows.Browser;

namespace HtmlUtilities
{
    public interface IHtmlWindow : IHtmlObject
    {
        void Alert(string alertText);
        bool Confirm(string confirmText);
        IScriptObject CreateInstance(string typeName, params object[] args);
        string CurrentBookmark { get; set; }
        object Eval(string code);
        void Navigate(Uri navigateToUri);
        IHtmlWindow Navigate(Uri navigateToUri, string target);
        IHtmlWindow Navigate(Uri navigateToUri, string target, string targetFeatuers);
        void NavigateToBookmark(string bookmark);
        string Prompt(string promptText);
    }

    internal class HtmlWindowWrapper : HtmlObjectWrapper, IHtmlWindow
    {
        private readonly HtmlWindow _window;
        public HtmlWindowWrapper(HtmlWindow window) : base(window)
        {
            _window = window;
        }

        public void Alert(string alertText)
        {
            _window.Alert(alertText);
        }

        public bool Confirm(string confirmText)
        {
            return _window.Confirm(confirmText);
        }

        public IScriptObject CreateInstance(string typeName, params object[] args)
        {
            return ScriptObjectFactory.GetScriptObject(_window.CreateInstance(typeName, args));
        }

        public string CurrentBookmark
        {
            get { return _window.CurrentBookmark; }
            set { _window.CurrentBookmark = value; }
        }

        public object Eval(string code)
        {
            return _window.Eval(code);
        }

        public void Navigate(Uri navigateToUri)
        {
            _window.Navigate(navigateToUri);
        }

        public IHtmlWindow Navigate(Uri navigateToUri, string target)
        {
            return ScriptObjectFactory.GetScriptObject<IHtmlWindow>(_window.Navigate(navigateToUri, target));
        }

        public IHtmlWindow Navigate(Uri navigateToUri, string target, string targetFeatuers)
        {
            return ScriptObjectFactory.GetScriptObject<IHtmlWindow>(_window.Navigate(navigateToUri, target, targetFeatuers));
        }

        public void NavigateToBookmark(string bookmark)
        {
            _window.NavigateToBookmark(bookmark);
        }

        public string Prompt(string promptText)
        {
            return _window.Prompt(promptText);
        }
    }
}